package com.java.demo;

import java.util.Random;
import java.util.Scanner;

public class guessNumber {
    public static void main(String[] args) {
        guess();
    }

    public static void guess() {
//        int num = (int)(Math.random()*100)+1; // ->[1,100]
        Random random = new Random();
        int num = random.nextInt(100) + 1;
        System.out.println(num);

        while (true) {
            System.out.println("input a number: ");
            int guessNum = new Scanner(System.in).nextInt();

            if (num == guessNum) {
                System.out.println("guess right!");
                break;
            }
            else if(num > guessNum){
                System.out.println("guess smaller!");
            }
            else {
                System.out.println("guess greater!");
            }
        }
    }

}
